package dyyx.buf;

import java.util.ArrayList;
import java.util.List;

import io.netty.buffer.ByteBuf;
import io.netty.buffer.PooledByteBufAllocator;
import io.netty.util.ResourceLeakDetector;

public class ByteBufLeakTest {
	
	
    private static final int SIZE = 1024 * 1024;

    
    private static List<ByteBuf> list = new ArrayList<ByteBuf>();
    
	public static void main(String[] args) throws Exception {
		// -Dio.netty.leakDetectionLevel=advanced
		// -Dio.netty.leakDetectionLevel=PARANOID
        // ResourceLeakDetector
		
		// ResourceLeakDetector<ByteBuf> ld = new ResourceLeakDetector<ByteBuf>();
		
        // ResourceLeakDetector<ByteBuf> detector = new ResourceLeakDetector(ByteBuf.class);
        // detector.setLevel(ResourceLeakDetector.Level.PARANOID);
        
		while(true){
			
			long start = System.currentTimeMillis();
		    ByteBuf buf = PooledByteBufAllocator.DEFAULT.directBuffer(SIZE);
			long end = System.currentTimeMillis();
            long time = end - start;
		    list.add(buf);
		    
		    System.out.println(list.size()+",time="+time);
		    
		    Thread.sleep(1000);

		}
	   
		
	}
	

	

	
}
